/*
 ============================================================================
 Name        : Set_CGI.c
 Author      : liuzhanchun
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#if 1
#define SERVER_NAME cgiServerName
#endif
#if 0
#define SERVER_NAME "www.boutell.com"
#endif

/* You may need to change this, particularly under Windows;
	it is a reasonable guess as to an acceptable place to
	store a saved environment in order to test that feature.
	If that feature is not important to you, you needn't
	concern yourself with this. */

#ifdef WIN32
#define SAVED_ENVIRONMENT "c:\\cgicsave.env"
#else
#define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
#endif /* WIN32 */

#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
#include "config_ini.h"

int cgiMain() {

	char maintenance[16] = {0};
	cgiFormString("maintenance", maintenance, 16);
  fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","maintenance",maintenance);

	char mon[16] = {0};
	cgiFormString("mon", mon, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","mon",mon);

	char tues[16] = {0};
	cgiFormString("tues", tues, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","tues",tues);

	char wed[16] = {0};
	cgiFormString("wed", wed, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","wed",wed);

	char thurs[16] = {0};
	cgiFormString("thurs", thurs, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","thurs",thurs);

	char fri[16] = {0};
	cgiFormString("fri", fri, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","fri",fri);

	char sat[16] = {0};
	cgiFormString("sat", sat, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","sat",sat);

	char sun[16] = {0};
	cgiFormString("sun", sun, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","sun",sun);

	char rebootTimeSelect[16] = {0};
	cgiFormString("rebootTimeSelect", rebootTimeSelect, 16);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","rebootTimeSelect",rebootTimeSelect);

	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html; charset=UTF-8");

	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>web 管理</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1></H1>\n");

	//存储数据
	configFileStrSet("/boa/my.ini","maintenance",maintenance);
  configFileStrSet("/boa/my.ini","mon",mon);
	configFileStrSet("/boa/my.ini","tues",tues);
	configFileStrSet("/boa/my.ini","wed",wed);
	configFileStrSet("/boa/my.ini","thurs",thurs);
	configFileStrSet("/boa/my.ini","fri",fri);
	configFileStrSet("/boa/my.ini","sat",sat);
	configFileStrSet("/boa/my.ini","sun",sun);
	configFileStrSet("/boa/my.ini","rebootTimeSelect",rebootTimeSelect);

	configFileStrSet("/boa/my2.ini","maintenance",maintenance);
  configFileStrSet("/boa/my2.ini","mon",mon);
	configFileStrSet("/boa/my2.ini","tues",tues);
	configFileStrSet("/boa/my2.ini","wed",wed);
	configFileStrSet("/boa/my2.ini","thurs",thurs);
	configFileStrSet("/boa/my2.ini","fri",fri);
	configFileStrSet("/boa/my2.ini","sat",sat);
	configFileStrSet("/boa/my2.ini","sun",sun);
	configFileStrSet("/boa/my2.ini","rebootTimeSelect",rebootTimeSelect);

  fprintf(cgiOut, "maintenance=%s\n", maintenance);
	fprintf(cgiOut, "mon=%s\n", mon);
	fprintf(cgiOut, "rebootTimeSelect=%s\n", rebootTimeSelect);
  
	//刷新页面
	fprintf(cgiOut, "<meta http-equiv=Refresh content=0;URL=../manager.html\n");
	fprintf(cgiOut, "</BODY></HTML>\n");

	return 0;
}
